<?php

namespace Modules\Chinadmin\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FormModel extends BaseModel
{

    public $table = 'ca_form';
    public $primaryKey = 'form_id';


    /**
     * 获取
     *
     * @param string $value
     * @return string
     */
    public function getSearchExtendAttribute($value){
        return json_decode($value,true);
    }

    /**
     * select table_name from information_schema.tables where table_schema='数据库表名'
     *
     * select ORDINAL_POSITION as Colorder,Column_Name as ColumnName,COLUMN_COMMENT as DeText
from information_schema.columns where table_schema = '数据库名称' and table_name = '表名'
order by ORDINAL_POSITION asc
     *
     * https://www.cnblogs.com/ZengJiaLin/p/11653915.html
     *
     **/
    static public function getTableName(){

        //$table_name = FormModel::groupBy('table_name')->pluck('table_name')->toArray();
        $table_name = DB::select('select table_name from information_schema.tables where table_schema = :table_schema', [':table_schema'=>config('database.connections.mysql.database')]);
        foreach($table_name as $kf => $vf){
            unset($table_name[$kf]);
            $table_name[$vf->table_name] = $vf->table_name;
        }
        return $table_name;

    }

    /**
     * select table_name from information_schema.tables where table_schema='数据库表名'
     *
     * select ORDINAL_POSITION as Colorder,Column_Name as ColumnName,COLUMN_COMMENT as DeText
    from information_schema.columns where table_schema = '数据库名称' and table_name = '表名'
    order by ORDINAL_POSITION asc
     *
     * https://www.cnblogs.com/ZengJiaLin/p/11653915.html
     *
     **/
    static public function getFieldName(){

        $table_name = FormModel::groupBy('table_name')->pluck('table_name')->toArray();

//        $table_name = DB::select("select ORDINAL_POSITION as Colorder,Column_Name as ColumnName,COLUMN_COMMENT as DeText
//    from information_schema.columns where table_schema = 'chinadmin' and table_name = 'ca_article_classification'
//    order by ORDINAL_POSITION asc");
//
//        d($table_name);

//        foreach($table_name as $kf => $vf){
//            unset($table_name[$kf]);
//            $table_name[$vf->table_name] = $vf->table_name;
//        }
//        return $table_name;


        return [];

    }


}
